<template>
	<view class="winapp">
		<web-view v-if="showMenu" :webview-styles="webviewStyles" :src="mrsUrl" @message="handleMessage" @onPostMessage="handleMessage"></web-view>
	</view>
</template>


<script>
	let _this;
	let uhfSFHelper = uni.requireNativePlugin("UhfEda51KModule");
	export default {
		data() {
			return {
				showMenu: false,
				mrsUrl:'',
				webviewStyles: {
					progress: {
						color: '#FF3333',
					}
				},
				rfidList:[],
				startFlag: false,
				usermsg: {}
			}
		},
		onLoad: function(option) {
			var _this = this;
			console.log(option.data);
			// var data = uni.getStorageSync('usermsg')
			// uni.removeStorageSync('usermsg')//销毁缓存数据
			if(JSON.parse(option.data).id == 'receiveNew'){
				var url = {
					receiveUrl:JSON.parse(option.data).url.receiveUrl||'',
					logUrl:JSON.parse(option.data).url.logUrl ||'',
					receiveUpUrl:JSON.parse(option.data).url.receiveUpUrl ||'',
					WMS3LIKU:JSON.parse(option.data).url.WMS3LIKU ||'',
				}
				var data = "?sessionid="+JSON.parse(option.data).seesionID+'&userid='+ JSON.parse(option.data).userid +"&domain="+JSON.parse(option.data).domain+"&corp="+JSON.parse(option.data).corp+"&url="+JSON.stringify(url)
				// var data = "?seesionid="+JSON.parse(option.data).seesionID+'&userid='+ JSON.parse(option.data).userid +"&domain="+JSON.parse(option.data).domain+"&corp="+JSON.parse(option.data).corp+"&url="+JSON.stringify(url)
				_this.mrsUrl = _this.$store.getters.getMrsUrl+ JSON.parse(option.data).aimView + data
			}else{
				_this.mrsUrl = _this.$store.getters.getMrsUrl + JSON.parse(option.data).aimView +'?usermsg=' + option.data
			}
			_this.showMenu = true
		},
		mounted:function(){
		},
		watch: {
		    rfidList () {
				var _this = this;
				if(!_this.startFlag){
					return
				}
				console.log(_this.rfidList)
		        _this.$scope.$getAppWebview().children()[0].evalJS(`requestStart(${JSON.stringify(_this.rfidList)})`);
		    }
		},
		methods:{
			handleMessage(evt) {
				var _this = this;  
				console.log(evt.detail.data)
				if(evt.detail.data[0].action === 'goBack'){
					const eventChannel = this.getOpenerEventChannel();
					eventChannel.emit('acceptDataFromOpenedPage', {});
					uni.navigateBack()
				}
				if(evt.detail.data[0].action === 'logout'){
					_this.appUtil.logout()
				}
				if(evt.detail.data[0].action === 'rfidInit'){
					_this.rfidList = []
					_this.init()
					_this.$scope.$getAppWebview().children()[0].evalJS(`requestInit()`);
				}
				if(evt.detail.data[0].action === 'rfidStart'){
					_this.releat()
					_this.startFlag = true;
				}
				if(evt.detail.data[0].action === 'rfidStop'){
					_this.startFlag = false;
					_this.stop()
					_this.$scope.$getAppWebview().children()[0].evalJS(`requestStop()`);
				}
			},
			 init() {
			 	var _this = this;
			 	uhfSFHelper.doInitDevice(result => {
			 		if (result) {
			 			_this.rfidList.push(result)
			 		}
			 	})
			 },
			 releat() {
			 	uhfSFHelper.doStartScan(true);
			 },
			 stop() {
			 	uhfSFHelper.doStopScan();
			 },
			 release() {
			 	uhfSFHelper.doReleaseDevice();
			 }
		}
	}
</script>

<style>
	@import url("../../static/css/base.css");
</style>